package org.lzy.aibg.dao.impl;

import org.lzy.aibg.dao.UserDao;
import org.lzy.aibg.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class UserDaoImpl implements UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 查询所有用户
     * @return 用户列表
     */
    @Override
    public List<User> selectAll() {
        System.out.println("getAll in UserDaoImpl");
        String sql = "select id,name,gender,age,class as classes from user;";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(User.class));
    }
}
